package com.zxs.infra.basic.service.impl;

import com.zxs.infra.basic.entity.SubjectInfo;
import com.zxs.infra.basic.entity.dto.SubjectInfoDTO;
import com.zxs.infra.basic.mapper.SubjectInfoMapper;
import com.zxs.infra.basic.service.SubjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 题目表(SubjectInfo)表服务实现类
 *
 * @author makejava
 * @since 2025-11-12 21:01:30
 */
@Service("subjectInfoService")
public class SubjectInfoServiceImpl implements SubjectInfoService {
    @Autowired
    private SubjectInfoMapper subjectInfoMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectInfo queryById(Integer id) {
        return this.subjectInfoMapper.queryById(id);
    }


    /**
     * 新增数据
     *
     * @param subjectInfo 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectInfo insert(SubjectInfo subjectInfo) {
        this.subjectInfoMapper.insert(subjectInfo);
        return subjectInfo;
    }

    /**
     * 修改数据
     *
     * @param subjectInfo 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectInfo update(SubjectInfo subjectInfo) {
        this.subjectInfoMapper.update(subjectInfo);
        return this.queryById(subjectInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.subjectInfoMapper.deleteById(id) > 0;
    }

    /**
     * 计算题目总数数量
     * @param categoryId
     * @param labelId
     * @param subjectDifficult
     * @return
     */
    @Override
    public int countByCondition(Integer categoryId, Integer labelId, String subjectDifficult) {
        return subjectInfoMapper.getCountSubjectInfo(categoryId,labelId,subjectDifficult);
    }

    @Override
    public List<SubjectInfoDTO> querySubjectInfoByPage(SubjectInfo subjectInfo, Integer categoryId, Integer labelId, int start, Integer pageSize) {
        return subjectInfoMapper.querySubjectInfoByPage(subjectInfo, categoryId, labelId, start, pageSize);
    }
}
